﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebComponents;
using WebComponents.Data;
using WebComponents.Security;
using GBIT.Web;

public partial class SetLanguage : UserControlBase {
  protected void Page_Load(object sender, EventArgs e) {
    if (!Page.IsPostBack) {
      grvLanguage.DataSource = ResourceValueController.GetByCultureID(cmbLanguage.SelectedValue);
      grvLanguage.DataBind();
    }   
    SaveEnabled = true;
    this.Title = "Ngôn ngữ";
    this.TaskTitle = "Cập nhật";
  }
  protected void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e) {
    grvLanguage.DataSource = ResourceValueController.GetByCultureID(cmbLanguage.SelectedValue);
    grvLanguage.DataBind();
  }

  protected void grvLanguage_PageIndexChanging(object sender, GridViewPageEventArgs e) {
    grvLanguage.PageIndex = e.NewPageIndex;
    grvLanguage.DataSource = ResourceValueController.GetByCultureID(cmbLanguage.SelectedValue);
    grvLanguage.DataBind();
  }
  protected override void OnSaveRecord() {
    bool flag = false;
    foreach (GridViewRow row in grvLanguage.Rows) {
      if (((CheckBox)row.FindControl("chkSelect")).Checked) {
        flag = true;
        ResourceValueInfo res = ResourceValueController.GetByResourceValueID(ConvertType.ToInt(((CheckBox)row.FindControl("chkSelect")).ToolTip));
        if (res != null) {
          TextBox txtValue = (TextBox)row.FindControl("txtValue");
          if (txtValue != null && txtValue.Text.Trim() != "") {
            res.Value = txtValue.Text.Trim();
            ResourceValueController.Update(res);
          }
        }
      }
    }
    if (!flag) {
      Security.ShowClientMessage(Page, "Bạn chưa chọn mục cần sửa thông tin");
    } else {
      grvLanguage.DataSource = ResourceValueController.GetByCultureID(cmbLanguage.SelectedValue);
      grvLanguage.DataBind();
      Security.ShowClientMessage(Page, "Cập nhật thông tin ngôn ngữ thành công");
    }
  }
  
}
